{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[[0.63691638 1.00888646]\n",
      " [0.98104071 0.71464848]\n",
      " [0.53045677 0.86787772]\n",
      " [0.52933457 0.99035327]\n",
      " [1.30816784 0.18318052]\n",
      " [1.00150449 0.76599927]\n",
      " [1.17727379 0.41066295]\n",
      " [1.1770792  0.25121328]\n",
      " [1.21662224 0.39419461]\n",
      " [0.41688204 0.92208153]\n",
      " [1.25964317 0.29796747]\n",
      " [0.6207708  0.77981947]\n",
      " [0.62651563 0.94174298]\n",
      " [0.89914386 0.60501762]\n",
      " [0.4710283  1.09252755]\n",
      " [0.8636349  0.72497116]\n",
      " [0.53103929 1.21656226]\n",
      " [0.6676152  1.13091688]\n",
      " [1.37302158 0.43737148]\n",
      " [0.96797531 0.68350607]\n",
      " [1.40109625 0.0420355 ]\n",
      " [0.61318315 1.27286011]\n",
      " [0.62503427 1.32643287]\n",
      " [1.46724362 0.12979033]\n",
      " [0.63674949 0.98010607]\n",
      " [0.80056196 0.74250225]\n",
      " [0.89531845 0.76832852]\n",
      " [0.83582018 0.70519348]\n",
      " [0.66640753 0.89061656]\n",
      " [0.5949296  0.81474704]\n",
      " [0.79081336 0.59942633]\n",
      " [0.4471341  0.96854606]\n",
      " [0.98074124 0.68333422]\n",
      " [0.61597685 0.86735893]\n",
      " [0.86431099 0.80211067]\n",
      " [1.38127556 0.24300432]\n",
      " [0.57349448 1.09538446]\n",
      " [1.45395648 0.24053507]\n",
      " [1.28164137 0.42758498]\n",
      " [1.28126528 0.428383  ]\n",
      " [1.34697778 0.14941988]\n",
      " [1.37531942 0.36251849]\n",
      " [0.71186144 0.93283592]\n",
      " [0.72110358 1.02549533]\n",
      " [0.64540062 1.05054645]\n",
      " [0.87120218 0.70047977]\n",
      " [0.83968518 0.87089846]\n",
      " [0.56981318 1.09032596]\n",
      " [1.13487033 0.79822058]\n",
      " [1.37579521 0.2053395 ]\n",
      " [0.96981872 0.71310882]\n",
      " [0.87987516 0.65318279]\n",
      " [0.71660956 0.72032606]\n",
      " [0.9270228  0.64327982]\n",
      " [0.57971918 0.92390885]\n",
      " [0.65261866 0.65848346]\n",
      " [0.94687968 0.8841956 ]\n",
      " [0.97509585 0.70594047]\n",
      " [0.81135545 0.81132319]\n",
      " [0.52106349 0.87584855]\n",
      " [0.75291026 0.86022486]\n",
      " [1.24964961 0.2974483 ]\n",
      " [1.23896101 0.3982748 ]\n",
      " [0.75154788 0.52592793]\n",
      " [0.85132991 0.85538353]\n",
      " [0.77833311 0.64731004]\n",
      " [1.20788561 0.19221242]\n",
      " [1.30103817 0.24797847]\n",
      " [0.54434747 0.90608589]\n",
      " [1.39969517 0.46690057]\n",
      " [1.28079261 0.42836444]\n",
      " [1.47314384 0.25779734]\n",
      " [1.00312285 0.7701969 ]\n",
      " [0.8790679  0.87763648]\n",
      " [0.59908719 0.99061173]\n",
      " [1.17859525 0.46594503]\n",
      " [0.5055171  0.67606961]\n",
      " [0.65922472 0.9164523 ]\n",
      " [1.52903692 0.19089077]\n",
      " [1.50879392 0.22065477]\n",
      " [0.84952244 0.82074561]\n",
      " [0.67062521 1.0347849 ]\n",
      " [0.7031292  0.93381025]\n",
      " [1.4392432  0.20556408]\n",
      " [0.60180171 1.12014142]\n",
      " [1.26006321 0.        ]\n",
      " [1.37309265 0.23899306]\n",
      " [0.39622896 1.10651165]\n",
      " [0.47509181 0.99423711]\n",
      " [0.70243828 0.56267979]\n",
      " [0.85824552 0.82289331]\n",
      " [1.31695382 0.27511658]\n",
      " [1.38013912 0.2409009 ]\n",
      " [1.33988383 0.28530815]\n",
      " [1.49948327 0.39243011]\n",
      " [0.56749685 1.03914865]\n",
      " [0.91271521 0.61942642]\n",
      " [1.30781891 0.43375651]\n",
      " [0.59248127 0.94609053]\n",
      " [0.51084741 0.93941988]]\n",
      "[[7.53055566 1.13595263 7.25089518]\n",
      " [0.         9.17388605 1.1162895 ]]\n"
     ]
    }
   ],
   "source": [
    "from sklearn.decomposition import NMF\n",
    "from sklearn.datasets.samples_generator import make_blobs\n",
    "\n",
    "\n",
    "centers = [[5, 10, 5], [10, 4, 10], [6, 8, 8]]\n",
    "X, _ = make_blobs(centers=centers) # 以centers为中心生成数据\n",
    "n_components = 2 # 潜在变量的个数\n",
    "model = NMF(n_components=n_components)\n",
    "model.fit(X)\n",
    "W = model.transform(X) # 分解后的矩阵\n",
    "H = model.components_\n",
    "print(W)\n",
    "print(H)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.8.3"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
